home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / clang / gnumake.zip / PATCHES.OS2 < prev    next >
Text File  |  1994-06-07  |  30KB  |  1,129 lines

  1. Only in new: README.OS2
  2. Only in new: patches.os2
  3. Only in new: Makefile.os2
  4. Only in new/glob: Makefile.os2
  5. Only in new: make.def
  6. Only in new: config.h
  7. diff -cbr orig/function.c new/function.c
  8. *** orig/function.c    Fri Mar 04 07:36:26 1994
  9. --- new/function.c    Tue Jun 07 17:39:16 1994
  10. ***************
  11. *** 377,388 ****
  12. --- 377,394 ----
  13.           break;
  14.         }
  15.   
  16. + #ifndef __EMX__
  17.       pid = vfork ();
  18.       if (pid < 0)
  19.         perror_with_name (error_prefix, "fork");
  20.       else if (pid == 0)
  21.         child_execute_job (0, pipedes[1], argv, envp);
  22.       else
  23. + #else
  24. +       if((pid = child_execute_job(0,pipedes[1], argv, environ)) < 0) {
  25. +         perror_with_name (error_prefix, "spawn");
  26. +       }
  27. + #endif
  28.         {
  29.           /* We are the parent.  */
  30.   
  31. diff -cbr orig/job.c new/job.c
  32. *** orig/job.c    Tue May 10 22:00:40 1994
  33. --- new/job.c    Tue Jun 07 18:40:28 1994
  34. ***************
  35. *** 21,32 ****
  36.   #include "job.h"
  37.   #include "file.h"
  38.   #include "variable.h"
  39.   
  40.   /* Default path to search for executables.  */
  41.   static char default_path[] = ":/bin:/usr/bin";
  42.   /* Default shell to use.  */
  43.   char default_shell[] = "/bin/sh";
  44.   
  45.   /* If NGROUPS_MAX == 0 then try other methods for finding a real value.  */
  46.   #if defined (NGROUPS_MAX) && NGROUPS_MAX == 0
  47. --- 21,43 ----
  48.   #include "job.h"
  49.   #include "file.h"
  50.   #include "variable.h"
  51. + #ifdef __EMX__
  52. + #include <process.h>
  53. + #endif
  54. + #ifdef HAVE_FCNTL_H
  55. + #include <fcntl.h>
  56. + #endif
  57.   
  58. + #ifndef __EMX__
  59.   /* Default path to search for executables.  */
  60.   static char default_path[] = ":/bin:/usr/bin";
  61.   /* Default shell to use.  */
  62.   char default_shell[] = "/bin/sh";
  63. + #else
  64. + /* I don't know what would pass for reasonable under OS/2 */
  65. + static char default_path[] = "\\os2;\\bin;\\usr\\bin";
  66. + char default_shell[] = "\\os2\\cmd.exe";
  67. + #endif
  68.   
  69.   /* If NGROUPS_MAX == 0 then try other methods for finding a real value.  */
  70.   #if defined (NGROUPS_MAX) && NGROUPS_MAX == 0
  71. ***************
  72. *** 650,655 ****
  73. --- 661,667 ----
  74.   #endif
  75.   
  76.         child->remote = 0;
  77. + #ifndef __EMX__
  78.         child->pid = vfork ();
  79.         if (child->pid == 0)
  80.       {
  81. ***************
  82. *** 665,670 ****
  83. --- 677,696 ----
  84.         perror_with_name ("vfork", "");
  85.         goto error;
  86.       }
  87. + #else
  88. +       child->pid = child_execute_job(child->good_stdin ? 0 : bad_stdin, 1,
  89. +                      argv, child->environment);
  90. +       /* if we've opened a pipe for the stdin of this command,
  91. +        * close it after the spawn, since we don't exec and let
  92. +        * the child handles croak of their own free will.
  93. +        */
  94. +       if(!child->good_stdin)
  95. +     close(bad_stdin);
  96. +       if(child->pid < 0) {
  97. +     unblock_sigs();
  98. +     goto error;
  99. +       }
  100. + #endif
  101.       }
  102.   
  103.     /* We are the parent side.  Set the state to
  104. ***************
  105. *** 979,994 ****
  106. --- 1005,1030 ----
  107.      STDIN_FD and STDOUT_FD are used as the process's stdin and stdout; ENVP is
  108.      the environment of the new program.  This function does not return.  */
  109.   
  110. + #ifndef __EMX__
  111.   void
  112. + #else
  113. + int
  114. + #endif
  115.   child_execute_job (stdin_fd, stdout_fd, argv, envp)
  116.        int stdin_fd, stdout_fd;
  117.        char **argv, **envp;
  118.   {
  119. + #ifdef __EMX__
  120. +   int oldstdin = dup(0), oldstdout = dup(1), rval;
  121. +   fcntl(oldstdin, F_SETFD, 1);
  122. +   fcntl(oldstdout, F_SETFD, 1);
  123. + #endif
  124.     if (stdin_fd != 0)
  125.       (void) dup2 (stdin_fd, 0);
  126.     if (stdout_fd != 1)
  127.       (void) dup2 (stdout_fd, 1);
  128.   
  129. + #ifndef __EMX__
  130.     /* Free up file descriptors.  */
  131.     {
  132.       register int d;
  133. ***************
  134. *** 996,1006 ****
  135.       for (d = 3; d < max; ++d)
  136.         (void) close (d);
  137.     }
  138.     /* Run the command.  */
  139.     exec_command (argv, envp);
  140.   }
  141.   
  142.   /* Search PATH for FILE.
  143.      If successful, store the full pathname in PROGRAM and return 1.
  144.      If not sucessful, return zero.  */
  145. --- 1032,1081 ----
  146.       for (d = 3; d < max; ++d)
  147.         (void) close (d);
  148.     }
  149.     /* Run the command.  */
  150.     exec_command (argv, envp);
  151. + #else
  152. +   rval = exec_command (argv, envp);
  153. +   dup2(oldstdin,0); dup2(oldstdout,1);
  154. +   close(oldstdin); close(oldstdout);
  155. +   return rval;
  156. + #endif
  157.   }
  158.   
  159. + /* Return one if the file is an internal SHELL command
  160. +    Return zero otherwise
  161. +  */
  162. + static int
  163. + is_shell_command(str)
  164. +      char *str;
  165. + {    
  166. +   register int j;
  167. + #ifndef __EMX__    
  168. +   static char *sh_cmds[] = { "cd", "eval", "exec", "exit", "login",
  169. +                              "logout", "set", "umask", "wait", "while", "for",
  170. +                              "case", "if", ":", ".", "break", "continue",
  171. +                              "export", "read", "readonly", "shift", "times",
  172. +                              "trap", "switch", 0 };
  173. +   for (j = 0; sh_cmds[j] != 0; ++j)
  174. +     if (streq (sh_cmds[j], str))
  175. +       return 1;
  176. + #else
  177. +   static char *sh_cmds[] = {
  178. +     "call","cd","chcp","chdir","cls","copy","date","del","detach",
  179. +     "dir","do","echo","else","endlocal","erase","errorlevel","exist",
  180. +     "exit","extproc","for","goto","if","in","keys","md","mkdir","move",
  181. +     "not","path","pause","prompt","rd","rem","ren","rename","rmdir",
  182. +     "set","setlocal","shift","start","time","type","ver","verify","vol",0
  183. +   };
  184. +   /* Shell command can be either upper or lower case */
  185. +   for (j = 0; sh_cmds[j] != 0; ++j)
  186. +     if(stricmp(sh_cmds[j], str) == 0)
  187. +       return 1;
  188. + #endif          
  189. +   return 0;
  190. + }
  191.   /* Search PATH for FILE.
  192.      If successful, store the full pathname in PROGRAM and return 1.
  193.      If not sucessful, return zero.  */
  194. ***************
  195. *** 1012,1018 ****
  196. --- 1087,1097 ----
  197.     if (path == 0 || path[0] == '\0')
  198.       path = default_path;
  199.   
  200. + #ifndef __EMX__
  201.     if (index (file, '/') != 0)
  202. + #else
  203. +   if (index(file,'/') != 0 || index (file, '\\') != 0 || file[1] == ':')
  204. + #endif
  205.       {
  206.         strcpy (program, file);
  207.         return 1;
  208. ***************
  209. *** 1043,1055 ****
  210. --- 1122,1148 ----
  211.   #endif    /* Have getgroups.  */
  212.   
  213.         len = strlen (file) + 1;
  214. + #ifdef __EMX__
  215. +       /* the standard OS/2 behavior is to look in CWD */
  216. +       {
  217. +     struct stat st;
  218. +     if(stat(file,&st) == 0) {
  219. +       strcpy(program,file);
  220. +       return 1;
  221. +     }
  222. +       }
  223. + #endif
  224.         do
  225.       {
  226.         struct stat st;
  227.         int perm;
  228.         char *p;
  229.   
  230. + #ifndef __EMX__
  231.         p = index (path, ':');
  232. + #else
  233. +       p = index (path, ';');
  234. + #endif
  235.         if (p == 0)
  236.           p = path + strlen (path);
  237.   
  238. ***************
  239. *** 1094,1110 ****
  240.     return 0;
  241.   }
  242.   
  243.   /* Replace the current process with one running the command in ARGV,
  244.      with environment ENVP.  This function does not return.  */
  245.   
  246.   void
  247.   exec_command (argv, envp)
  248.        char **argv, **envp;
  249.   {
  250.     char *shell, *path;
  251.     PATH_VAR (program);
  252.     register char **ep;
  253.     shell = path = 0;
  254.     for (ep = envp; *ep != 0; ++ep)
  255.       {
  256. --- 1187,1323 ----
  257.     return 0;
  258.   }
  259.   
  260. + #ifdef __EMX__
  261. +  
  262. + /* Using something DOSISH all executables have extentions 
  263. + /* So append these and then search for them in the path.
  264. +  */
  265. + static int
  266. + emx_search_path (file, path, program)
  267. +      char *file, *path, *program;
  268. + {
  269. +   static char *suffixes[] = { ".exe", ".com", ".cmd", ".bat", NULL };
  270. +   char *dot, tmp[PATH_MAX]; 
  271. +   int i,namelen;
  272. +   if (search_path(file,path,program)==1)
  273. +     return 1;
  274. +   if ((namelen = strlen(file)) < 4 || file[namelen-4] != '.') {
  275. +     for (i = 0; suffixes[i]; i++) {
  276. +       strcpy(tmp,file);
  277. +       strcat(tmp,suffixes[i]);
  278. +       if (search_path(tmp,path,program) == 1) {
  279. +     return 1;
  280. +       }
  281. +     }
  282. +   }
  283. +   return 0;
  284. + }
  285. + /* Have people call emx_search_path in the remainder of the program.
  286. + /* This will mimic regular behaviour.
  287. +  */
  288. + #define search_path emx_search_path 
  289. + /* Return zero if the file is not a script.
  290. +    Return one if it is a script.
  291. +  */
  292. + static int
  293. + is_script(file)
  294. +     char *file;
  295. + {
  296. +     static char *script_suffixes[] = { ".cmd", ".bat", NULL };
  297. +     int i, namelen;
  298. +     char *tmp;
  299. +     struct stat st;
  300. +     PATH_VAR(prog);
  301. +     
  302. +     /* setup a temporary file name, which is lower case. */
  303. +     namelen = strlen(file);
  304. +     tmp = malloc(namelen+5);
  305. +     strcpy(tmp,file); 
  306. +     strlwr(tmp);
  307. +     for (i=0; script_suffixes[i]; i++) {
  308. +         /* does it contain the extension */
  309. +         if (strstr(file,script_suffixes[i])!=NULL) {
  310. +             /* the user thinks it should be a script */
  311. +             return 1;   
  312. +         } else {
  313. +             if (file[namelen-4] == '.') {
  314. +                 /* it did have an extension so it can't be a script */
  315. +                 return 0;
  316. +             }  else {
  317. +                 /* append the extension and see if the file exists. */
  318. +                 tmp[namelen] = '\0';
  319. +                 strcat(tmp,script_suffixes[i]);
  320. +                 if(search_path (tmp, getenv("PATH"), prog)==1)
  321. +                      return 1;
  322. +             }
  323. +         }
  324. +     }
  325. +     /* should not be a script here */
  326. +     return 0;
  327. + }
  328. + char *
  329. + os2_shell(for_cmd)
  330. +   int for_cmd;
  331. + {
  332. +   char *make_shell,*comspec,*os2_shell;
  333. +   make_shell = getenv("MAKE_SHELL");
  334. +   comspec = getenv("COMSPEC");
  335. +   os2_shell = getenv("OS2_SHELL");
  336. +   if(make_shell != NULL && !for_cmd)
  337. +     return make_shell;
  338. +   else if(comspec != NULL)
  339. +     return comspec;
  340. +   else if(os2_shell != NULL)
  341. +     return os2_shell;
  342. +   else
  343. +     return default_shell;
  344. + }
  345. + int
  346. + is_cmd_exe(shell)
  347. +   char *shell;
  348. + {
  349. +   char basename[64];
  350. +   _splitpath(shell, NULL, NULL, basename, NULL);
  351. +   return (stricmp(basename,"4os2") == 0 || stricmp(basename,"cmd") == 0) ||
  352. +          (stricmp(basename,"4dos") == 0 || stricmp(basename,"command") == 0);
  353. + }
  354. + #else
  355. + static int
  356. + is_script(file)
  357. +      char *file;
  358. + {    return 0;
  359. + }
  360. + #endif
  361.   /* Replace the current process with one running the command in ARGV,
  362.      with environment ENVP.  This function does not return.  */
  363.   
  364. + #ifndef __EMX__
  365.   void
  366. + #else
  367. + int
  368. + #endif
  369.   exec_command (argv, envp)
  370.        char **argv, **envp;
  371.   {
  372.     char *shell, *path;
  373.     PATH_VAR (program);
  374.     register char **ep;
  375. ! #ifdef __EMX__
  376. !   int pid = -1;
  377. ! #endif
  378.     shell = path = 0;
  379.     for (ep = envp; *ep != 0; ++ep)
  380.       {
  381. ***************
  382. *** 1115,1120 ****
  383. --- 1328,1337 ----
  384.         else if (path != 0 && shell != 0)
  385.       break;
  386.       }
  387. + #ifdef __EMX__
  388. +   if (shell == 0)
  389. +     shell = os2_shell(0);
  390. + #endif
  391.   
  392.     /* Be the user, permanently.  */
  393.     child_access ();
  394. ***************
  395. *** 1123,1137 ****
  396.       error ("%s: Command not found", argv[0]);
  397.     else
  398.       {
  399.         /* Run the program.  */
  400.         execve (program, argv, envp);
  401.         if (errno == ENOEXEC)
  402.       {
  403.         PATH_VAR (shell_program);
  404.         char *shell_path;
  405.         if (shell == 0)
  406.           shell_path = default_shell;
  407.         else
  408.           {
  409.             if (search_path (shell, path, shell_program))
  410. --- 1340,1364 ----
  411.       error ("%s: Command not found", argv[0]);
  412.     else
  413.       {
  414. + #ifndef __EMX__
  415.         /* Run the program.  */
  416.         execve (program, argv, envp);
  417.         if (errno == ENOEXEC)
  418. + #else
  419. +       pid = spawnve(P_NOWAIT,program,
  420. +             (const char * const *)argv,
  421. +             (const char * const *)envp);
  422. +       if(pid == -1)
  423. + #endif      
  424.       {
  425.         PATH_VAR (shell_program);
  426.         char *shell_path;
  427.         if (shell == 0)
  428. + #ifdef __EMX__
  429.           shell_path = default_shell;
  430. + #else
  431. +         shell_path = os2_shell(1);
  432. + #endif
  433.         else
  434.           {
  435.             if (search_path (shell, path, shell_program))
  436. ***************
  437. *** 1146,1175 ****
  438.         if (shell_path != 0)
  439.           {
  440.             char **new_argv;
  441. !           int argc;
  442.   
  443.             argc = 1;
  444.             while (argv[argc] != 0)
  445.           ++argc;
  446.   
  447.             new_argv = (char **) alloca ((1 + argc + 1) * sizeof (char *));
  448.             new_argv[0] = shell_path;
  449. !           new_argv[1] = program;
  450.             while (argc > 0)
  451.           {
  452. !           new_argv[1 + argc] = argv[argc];
  453.             --argc;
  454.           }
  455.   
  456.             execve (shell_path, new_argv, envp);
  457.             perror_with_name ("execve: ", shell_path);
  458.           }
  459.       }
  460.         else
  461.       perror_with_name ("execve: ", program);
  462.       }
  463.     _exit (127);
  464.   }
  465.   
  466.   /* Figure out the argument list necessary to run LINE as a command.
  467. --- 1373,1423 ----
  468.         if (shell_path != 0)
  469.           {
  470.             char **new_argv;
  471. !           int argc, arg;
  472.   
  473.             argc = 1;
  474.             while (argv[argc] != 0)
  475.           ++argc;
  476.   
  477. +           arg = 0;
  478. + #ifdef __EMX__
  479. +           new_argv = (char **) alloca ((1 + argc + 2) * sizeof (char *));
  480. +           new_argv[0] = shell_path;
  481. +           new_argv[++arg] = "/c";
  482. + #else
  483.             new_argv = (char **) alloca ((1 + argc + 1) * sizeof (char *));
  484.             new_argv[0] = shell_path;
  485. ! #endif
  486. !           new_argv[++arg] = program;
  487.             while (argc > 0)
  488.           {
  489. !           new_argv[arg + argc] = argv[argc];
  490.             --argc;
  491.           }
  492.   
  493. +           /* Run the program.  */
  494. + #ifndef __EMX__
  495.             execve (shell_path, new_argv, envp);
  496.             perror_with_name ("execve: ", shell_path);
  497. + #else
  498. +           pid = spawnve(P_NOWAIT,shell_path,
  499. +                 (const char * const *)new_argv,
  500. +                 (const char * const *)envp);
  501. +           if(pid == -1)
  502. +         perror_with_name ("spawnve: ", shell_path);
  503. + #endif      
  504.           }
  505.       }
  506. + #ifndef __EMX__
  507.         else
  508.       perror_with_name ("execve: ", program);
  509. + #endif
  510.       }
  511. ! #ifndef __EMX__
  512.     _exit (127);
  513. + #else
  514. +   return pid;
  515. + #endif
  516.   }
  517.   
  518.   /* Figure out the argument list necessary to run LINE as a command.
  519. ***************
  520. *** 1189,1200 ****
  521.        char *line, **restp;
  522.        char *shell, *ifs;
  523.   {
  524.     static char sh_chars[] = "#;\"*?[]&|<>(){}$`^";
  525. !   static char *sh_cmds[] = { "cd", "eval", "exec", "exit", "login",
  526. !                  "logout", "set", "umask", "wait", "while", "for",
  527. !                  "case", "if", ":", ".", "break", "continue",
  528. !                  "export", "read", "readonly", "shift", "times",
  529. !                  "trap", "switch", 0 };
  530.     register int i;
  531.     register char *p;
  532.     register char *ap;
  533. --- 1437,1448 ----
  534.        char *line, **restp;
  535.        char *shell, *ifs;
  536.   {
  537. + #ifndef __EMX__
  538.     static char sh_chars[] = "#;\"*?[]&|<>(){}$`^";
  539. ! #else
  540. !   static char sh_chars[] = "&|<>^()";
  541. !   int is_cmd = 1;
  542. ! #endif
  543.     register int i;
  544.     register char *p;
  545.     register char *ap;
  546. ***************
  547. *** 1213,1221 ****
  548. --- 1461,1476 ----
  549.   
  550.     /* See if it is safe to parse commands internally.  */
  551.     if (shell == 0)
  552. + #ifndef __EMX__
  553.       shell = default_shell;
  554.     else if (strcmp (shell, default_shell))
  555.       goto slow;
  556. + #else
  557. +     shell = os2_shell(0);
  558. +   else
  559. +     if (!(is_cmd = is_cmd_exe(shell)))
  560. +     goto slow;
  561. + #endif
  562.   
  563.     if (ifs != 0)
  564.       for (ap = ifs; *ap != '\0'; ++ap)
  565. ***************
  566. *** 1243,1252 ****
  567.       {
  568.         /* Inside a string, just copy any char except a closing quote
  569.            or a backslash-newline combination.  */
  570. !       if (*p == '\'')
  571.           instring = 0;
  572.         else if (*p == '\\' && p[1] == '\n')
  573.           goto swallow_escaped_newline;
  574.         else if (*p == '\n' && restp != NULL)
  575.           {
  576.             /* End of the command line.  */
  577. --- 1498,1511 ----
  578.       {
  579.         /* Inside a string, just copy any char except a closing quote
  580.            or a backslash-newline combination.  */
  581. !       if (*p == instring)
  582.           instring = 0;
  583.         else if (*p == '\\' && p[1] == '\n')
  584.           goto swallow_escaped_newline;
  585. + #ifdef __EMX__
  586. +       else if (*p == '\\') /* except if guarded by \ */
  587. +         *ap++ = *++p;
  588. + #endif
  589.         else if (*p == '\n' && restp != NULL)
  590.           {
  591.             /* End of the command line.  */
  592. ***************
  593. *** 1304,1316 ****
  594.                 p = next_token (p) - 1;
  595.             }
  596.             }
  597. !         else if (p[1] != '\0')
  598.             /* Copy and skip the following char.  */
  599.             *ap++ = *++p;
  600.           break;
  601.   
  602.         case '\'':
  603. !         instring = 1;
  604.           break;
  605.   
  606.         case '\n':
  607. --- 1563,1585 ----
  608.                 p = next_token (p) - 1;
  609.             }
  610.             }
  611. !         else if (p[1] != '\0') {
  612. ! #ifdef __EMX__
  613. !           /* for OS/2, let's keep single \ before characters and numbers
  614. !          because \ is commonly used as path name separator */
  615. !           if (isalnum(p[1]))
  616. !         *ap++ = *p;
  617. ! #endif
  618.             /* Copy and skip the following char.  */
  619.             *ap++ = *++p;
  620. +         }
  621.           break;
  622.   
  623. + #ifdef __EMX__
  624. +       case '"':
  625. + #endif
  626.         case '\'':
  627. !         instring = *p;
  628.           break;
  629.   
  630.         case '\n':
  631. ***************
  632. *** 1345,1358 ****
  633.           /* If this argument is the command name,
  634.              see if it is a built-in shell command.
  635.              If so, have the shell handle it.  */
  636. !         if (i == 1)
  637. !           {
  638. !         register int j;
  639. !         for (j = 0; sh_cmds[j] != 0; ++j)
  640. !           if (streq (sh_cmds[j], new_argv[0]))
  641.               goto slow;
  642.             }
  643.           /* Ignore multiple whitespace chars.  */
  644.           p = next_token (p);
  645.           /* Next iteration should examine the first nonwhite char.  */
  646. --- 1614,1627 ----
  647.           /* If this argument is the command name,
  648.              see if it is a built-in shell command.
  649.              If so, have the shell handle it.  */
  650. !         if (i == 1) {
  651. !             if(is_shell_command(new_argv[0]))
  652. !           goto slow;
  653. ! #ifdef __EMX__
  654. !             if (is_script(new_argv[0]))
  655.               goto slow;
  656. + #endif                
  657.             }
  658.           /* Ignore multiple whitespace chars.  */
  659.           p = next_token (p);
  660.           /* Next iteration should examine the first nonwhite char.  */
  661. ***************
  662. *** 1379,1388 ****
  663.   
  664.     if (i == 1)
  665.       {
  666. !       register int j;
  667. !       for (j = 0; sh_cmds[j] != 0; ++j)
  668. !     if (streq (sh_cmds[j], new_argv[0]))
  669.         goto slow;
  670.       }
  671.   
  672.     if (new_argv[0] == 0)
  673. --- 1648,1659 ----
  674.   
  675.     if (i == 1)
  676.       {
  677. !       if (is_shell_command(new_argv[0]))
  678. !     goto slow;
  679. ! #ifndef __EMX__
  680. !       if (is_script(new_argv[0]))
  681.         goto slow;
  682. + #endif
  683.       }
  684.   
  685.     if (new_argv[0] == 0)
  686. ***************
  687. *** 1408,1424 ****
  688.          argument list.  */
  689.       
  690.       unsigned int shell_len = strlen (shell);
  691.       static char minus_c[] = " -c ";
  692.       unsigned int line_len = strlen (line);
  693. !     
  694. !     char *new_line = (char *) alloca (shell_len + (sizeof (minus_c) - 1)
  695.                         + (line_len * 2) + 1);
  696. -     
  697.       ap = new_line;
  698.       bcopy (shell, ap, shell_len);
  699.       ap += shell_len;
  700. !     bcopy (minus_c, ap, sizeof (minus_c) - 1);
  701. !     ap += sizeof (minus_c) - 1;
  702.       for (p = line; *p != '\0'; ++p)
  703.         {
  704.       if (restp != NULL && *p == '\n')
  705. --- 1679,1704 ----
  706.          argument list.  */
  707.       
  708.       unsigned int shell_len = strlen (shell);
  709. + #ifndef __EMX__
  710.       static char minus_c[] = " -c ";
  711. + #define MINUS_C_SIZE sizeof(minus_c)
  712. + #else
  713. +     char *minus_c = " /c ";
  714. + #define MINUS_C_SIZE (strlen(minus_c)+1)
  715. + #endif
  716.       unsigned int line_len = strlen (line);
  717. !     char *new_line;
  718. ! #ifdef __EMX__
  719. !     if(!is_cmd)
  720. !       minus_c = " -c ";
  721. ! #endif    
  722. !     new_line = (char *) alloca (shell_len + (MINUS_C_SIZE - 1)
  723.                         + (line_len * 2) + 1);
  724.       ap = new_line;
  725.       bcopy (shell, ap, shell_len);
  726.       ap += shell_len;
  727. !     bcopy (minus_c, ap, MINUS_C_SIZE - 1);
  728. !     ap += MINUS_C_SIZE - 1;
  729.       for (p = line; *p != '\0'; ++p)
  730.         {
  731.       if (restp != NULL && *p == '\n')
  732. ***************
  733. *** 1429,1455 ****
  734.       else if (*p == '\\' && p[1] == '\n')
  735.         {
  736.           /* Eat the backslash, the newline, and following whitespace,
  737. !            replacing it all with a single space (which is escaped
  738. !            from the shell).  */
  739.           p += 2;
  740.   
  741. !         /* If there is a tab after a backslash-newline,
  742. !            remove it from the source line which will be echoed,
  743. !            since it was most likely used to line
  744.              up the continued line with the previous one.  */
  745. !         if (*p == '\t')
  746.             strcpy (p, p + 1);
  747.   
  748.           p = next_token (p);
  749.           --p;
  750.           *ap++ = '\\';
  751.           *ap++ = ' ';
  752.           continue;
  753.         }
  754.   
  755. !     if (*p == '\\' || *p == '\''
  756. !         || isspace (*p)
  757. !         || index (sh_chars, *p) != 0)
  758.         *ap++ = '\\';
  759.       *ap++ = *p;
  760.         }
  761. --- 1709,1744 ----
  762.       else if (*p == '\\' && p[1] == '\n')
  763.         {
  764.           /* Eat the backslash, the newline, and following whitespace,
  765. !            replacing it all with a single space.  */
  766.           p += 2;
  767.   
  768. !         /* If there are tabs after a backslash-newline,
  769. !            remove them from the source line which will be echoed,
  770. !            since they were most likely used to line
  771.              up the continued line with the previous one.  */
  772. !         while (*p == '\t')
  773.             strcpy (p, p + 1);
  774.   
  775.           p = next_token (p);
  776.           --p;
  777. + #ifdef __EMX__
  778. +         if (!is_cmd)
  779. + #endif
  780.           *ap++ = '\\';
  781.           *ap++ = ' ';
  782.           continue;
  783.         }
  784.   
  785. !     if (*p == '\\' ||
  786. !         *p == '\'' ||
  787. ! #ifdef __EMX__
  788. !         *p == '"' ||
  789. ! #endif
  790. !         isspace (*p) ||
  791. !         index (sh_chars, *p) != 0)
  792. ! #ifdef __EMX__
  793. !       if(!is_cmd || index(sh_chars,*p) != 0)
  794. ! #endif
  795.         *ap++ = '\\';
  796.       *ap++ = *p;
  797.         }
  798. diff -cbr orig/job.h new/job.h
  799. *** orig/job.h    Wed Mar 23 16:13:32 1994
  800. --- new/job.h    Tue Jun 07 17:39:20 1994
  801. ***************
  802. *** 46,54 ****
  803.   extern void start_waiting_jobs ();
  804.   
  805.   extern char **construct_command_argv ();
  806.   extern void child_execute_job ();
  807.   extern void exec_command ();
  808.   extern unsigned int job_slots_used;
  809.   
  810.   #ifdef POSIX
  811. --- 46,58 ----
  812.   extern void start_waiting_jobs ();
  813.   
  814.   extern char **construct_command_argv ();
  815. + #ifndef __EMX__
  816.   extern void child_execute_job ();
  817.   extern void exec_command ();
  818. ! #else
  819. ! extern int child_execute_job ();
  820. ! extern int exec_command ();
  821. ! #endif
  822.   extern unsigned int job_slots_used;
  823.   
  824.   #ifdef POSIX
  825. diff -cbr orig/main.c new/main.c
  826. *** orig/main.c    Thu Apr 21 04:08:24 1994
  827. --- new/main.c    Tue Jun 07 17:39:22 1994
  828. ***************
  829. *** 396,401 ****
  830. --- 396,406 ----
  831.     PATH_VAR (current_directory);
  832.     char *directory_before_chdir;
  833.   
  834. + #ifdef __EMX__
  835. +   _response(&argc,&argv);
  836. +   _wildcard(&argc,&argv);
  837. + #endif
  838.     default_goal_file = 0;
  839.     reading_filename = 0;
  840.     reading_lineno_ptr = 0;
  841. ***************
  842. *** 607,616 ****
  843.        If it is a name with no slash, we can only hope that PATH did not
  844.        find it in the current directory.)  */
  845.   
  846.     if (current_directory[0] != '\0'
  847.         && argv[0] != 0 && argv[0][0] != '/' && index (argv[0], '/') != 0)
  848.       argv[0] = concat (current_directory, "/", argv[0]);
  849.     (void) define_variable ("MAKE_COMMAND", 12, argv[0], o_default, 0);
  850.   
  851.     /* Append the command-line variable definitions gathered above
  852. --- 612,636 ----
  853.        If it is a name with no slash, we can only hope that PATH did not
  854.        find it in the current directory.)  */
  855.   
  856. + #ifndef __EMX__
  857.     if (current_directory[0] != '\0'
  858.         && argv[0] != 0 && argv[0][0] != '/' && index (argv[0], '/') != 0)
  859.       argv[0] = concat (current_directory, "/", argv[0]);
  860. ! #else
  861. !   if (current_directory[0] != '\0' && /* there is a cwd */
  862. !       argv[0] != 0 &&            /* there is an argv[0] */
  863. !       (argv[0][0] != '/' &&        /* and it doesn't begin with slash */
  864. !       argv[0][0] != '\\' &&        /* or a backslash */
  865. !       argv[0][1] != ':') &&        /* or start with a drive letter */
  866. !       (index (argv[0], '/') != 0 ||    /*  it does contain a slash */
  867. !       index (argv[0], '\\') != 0))    /* or a backslash */
  868. !     argv[0] = concat (current_directory, "/", argv[0]);
  869. !   {
  870. !     char *cp;
  871. !     for(cp = argv[0]; *cp != '\0'; cp++)
  872. !       *cp = (*cp == '\\') ? '/' : *cp;
  873. !   }
  874. ! #endif
  875.     (void) define_variable ("MAKE_COMMAND", 12, argv[0], o_default, 0);
  876.   
  877.     /* Append the command-line variable definitions gathered above
  878. ***************
  879. *** 694,704 ****
  880.           /* This makefile is standard input.  Since we may re-exec
  881.              and thus re-read the makefiles, we read standard input
  882.              into a temporary file and read from that.  */
  883. !         static char name[] = "/tmp/GmXXXXXX";
  884.           FILE *outfile;
  885.   
  886.           /* Make a unique filename.  */
  887. !         (void) mktemp (name);
  888.   
  889.           outfile = fopen (name, "w");
  890.           if (outfile == 0)
  891. --- 714,724 ----
  892.           /* This makefile is standard input.  Since we may re-exec
  893.              and thus re-read the makefiles, we read standard input
  894.              into a temporary file and read from that.  */
  895. !         char name[PATH_MAX];
  896.           FILE *outfile;
  897.   
  898.           /* Make a unique filename.  */
  899. !         tmpnam (name);
  900.   
  901.           outfile = fopen (name, "w");
  902.           if (outfile == 0)
  903. ***************
  904. *** 1054,1060 ****
  905. --- 1074,1084 ----
  906.         fflush (stdout);
  907.         fflush (stderr);
  908.   
  909. + #ifndef __EMX__
  910.         exec_command (argv, environ);
  911. + #else
  912. +       exit(exec_command (argv, environ));
  913. + #endif
  914.         /* NOTREACHED */
  915.       }
  916.       }
  917. ***************
  918. *** 1337,1343 ****
  919.       {
  920.         /* Print a nice usage message.  */
  921.   
  922. -       if (print_version_flag)
  923.       print_version ();
  924.   
  925.         fprintf (stderr, "Usage: %s [options] [target] ...\n", program);
  926. --- 1361,1366 ----
  927. ***************
  928. *** 1758,1769 ****
  929.         if (print_version_flag)
  930.       print_version ();
  931.   
  932.         /* Wait for children to die.  */
  933.         for (err = status != 0; job_slots_used > 0; err = 0)
  934.       reap_children (1, err);
  935. -       /* Remove the intermediate files.  */
  936. -       remove_intermediates (0);
  937.   
  938.         if (print_data_base_flag)
  939.       print_data_base ();
  940. --- 1781,1792 ----
  941.         if (print_version_flag)
  942.       print_version ();
  943.   
  944. +       /* Remove the intermediate files.  */
  945. +       remove_intermediates (0);
  946.         /* Wait for children to die.  */
  947.         for (err = status != 0; job_slots_used > 0; err = 0)
  948.       reap_children (1, err);
  949.   
  950.         if (print_data_base_flag)
  951.       print_data_base ();
  952. diff -cbr orig/make.h new/make.h
  953. *** orig/make.h    Sat May 21 22:23:48 1994
  954. --- new/make.h    Tue Jun 07 17:39:22 1994
  955. ***************
  956. *** 321,327 ****
  957. --- 321,335 ----
  958.   #define    getcwd(buf, len)    getwd (buf)
  959.   #endif
  960.   
  961. + #if defined(sgi) || defined(__EMX__)
  962.   extern char **environ;
  963. + #else
  964. + #ifndef NSIG
  965. + #define NSIG 33
  966. + #endif
  967. + extern char **_environ;
  968. + #define environ _environ
  969. + #endif
  970.   
  971.   extern char *reading_filename;
  972.   extern unsigned int *reading_lineno_ptr;
  973. diff -cbr orig/read.c new/read.c
  974. *** orig/read.c    Tue May 03 00:35:24 1994
  975. --- new/read.c    Tue Jun 07 21:27:34 1994
  976. ***************
  977. *** 699,704 ****
  978. --- 699,709 ----
  979.   
  980.         /* Is this a static pattern rule: `target: %targ: %dep; ...'?  */
  981.         p = index (p2, ':');
  982. + #ifdef __EMX__
  983. +       /* allow path names with drive specifications (x:) */
  984. +       if (p != 0 && !isspace(p[1]))
  985. +         p = 0;
  986. + #endif
  987.         while (p != 0 && p[-1] == '\\')
  988.           {
  989.             register char *q = &p[-1];
  990. ***************
  991. *** 1228,1233 ****
  992. --- 1233,1242 ----
  993.                        pattern_percent, percent);
  994.           free (d->name);
  995.           d->name = savestring (buffer, o - buffer);
  996. + #ifdef __EMX__
  997. +         if (d->name[0] != '.')
  998. +           _fnlwr(d->name);
  999. + #endif
  1000.             }
  1001.         }
  1002.         
  1003. ***************
  1004. *** 1431,1438 ****
  1005. --- 1440,1456 ----
  1006.       {
  1007.         if (blank)
  1008.       {
  1009. + #ifdef __EMX__
  1010. +       while (*p != '\0' && !isblank (*p))
  1011. +         if (*p == stopchar && (stopchar != ':' || isblank(p[1]) || 
  1012. +                    p[1] == 0 || p[1] == ':' || p[1] == ';'))
  1013. +           break;
  1014. +         else
  1015. +           ++p;
  1016. + #else
  1017.         while (*p != '\0' && *p != stopchar && !isblank (*p))
  1018.           ++p;
  1019. + #endif
  1020.         if (*p == '\0')
  1021.           break;
  1022.       }
  1023. ***************
  1024. *** 1734,1739 ****
  1025. --- 1752,1759 ----
  1026.         if (!backslash)
  1027.       {
  1028.         p[-1] = '\0';
  1029. +       if (p - p2 > 2)
  1030. +         p[-2] = '\0'; /* kill one of multiple backslashes */
  1031.         break;
  1032.       }
  1033.   
  1034. ***************
  1035. *** 1934,1939 ****
  1036. --- 1954,1963 ----
  1037.           {
  1038.             free (old->name);
  1039.             old->name = newname;
  1040. + #ifdef __EMX__
  1041. +           if (old->name[0] != '.')
  1042. +         _fnlwr(old->name);
  1043. + #endif
  1044.           }
  1045.       }
  1046.   
  1047. ***************
  1048. *** 2004,2009 ****
  1049. --- 2028,2037 ----
  1050.               struct nameseq *elt = (struct nameseq *) xmalloc (size);
  1051.               elt->name = savestring (gl.gl_pathv[i],
  1052.                           strlen (gl.gl_pathv[i]));
  1053. + #ifdef __EMX__
  1054. +             if (old->name[0] != '.')
  1055. +               _fnlwr(elt->name);
  1056. + #endif
  1057.               elt->next = new;
  1058.               new = elt;
  1059.             }
  1060. diff -cbr orig/variable.c new/variable.c
  1061. *** orig/variable.c    Tue Apr 05 12:09:14 1994
  1062. --- new/variable.c    Tue Jun 07 17:39:24 1994
  1063. ***************
  1064. *** 366,371 ****
  1065. --- 366,372 ----
  1066.     v = define_variable ("SHELL", 5, default_shell, o_default, 0);
  1067.     v->export = v_export;        /* Always export SHELL.  */
  1068.   
  1069. + #ifndef __EMX__
  1070.     /* Don't let SHELL come from the environment.  */
  1071.     if (*v->value == '\0' || v->origin == o_env || v->origin == o_env_override)
  1072.       {
  1073. ***************
  1074. *** 373,378 ****
  1075. --- 374,388 ----
  1076.         v->origin = o_file;
  1077.         v->value = savestring (default_shell, strlen (default_shell));
  1078.       }
  1079. + #else
  1080. +     {
  1081. +       extern char *os2_shell(int);
  1082. +       char *cp = os2_shell(0);
  1083. +       v->value = savestring (cp, strlen(cp));
  1084. +       for(cp = v->value; *cp != '\0'; cp++)
  1085. +     *cp = (*cp == '\\' ? '/' : *cp);
  1086. +     }
  1087. + #endif
  1088.   
  1089.     /* Make sure MAKEFILES gets exported if it is set.  */
  1090.     v = define_variable ("MAKEFILES", 9, "", o_default, 0);
  1091. ***************
  1092. *** 610,615 ****
  1093. --- 620,628 ----
  1094.       --end;
  1095.     p = next_token (p);
  1096.   
  1097. +   /* don't try to do this for empty names */
  1098. +   if(end < beg)
  1099. +     return 0;
  1100.     /* Expand the name, so "$(foo)bar = baz" works.  */
  1101.     name = (char *) alloca (end - beg + 1);
  1102.     bcopy (beg, name, end - beg);
  1103.